package org.slf4jx.autoconfiguration;

import org.slf4jx.core.Slf4jxFilter;
import org.springframework.boot.autoconfigure.web.servlet.ConditionalOnMissingFilterBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动注入filter 用于控制 MDC
 * @author jjliu
 * @date 2023/1/15
 */
@Configuration
public class Slf4jxAutoConfiguration {

    @ConditionalOnMissingFilterBean({Slf4jxFilter.class})
    @Bean
    public FilterRegistrationBean authFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean<Slf4jxFilter>(new Slf4jxFilter());
        registration.addUrlPatterns("/*");
        registration.setName("slf4jxFilter");
        registration.setOrder(Integer.MIN_VALUE);
        return registration;
    }

}
